package com.zmx.product.repository;

import com.zmx.common.common.repository.BaseRepository;
import com.zmx.product.entity.Product;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author zhaomxr
 */
public interface ProductRepository extends BaseRepository<Product> {

    @Query(value = "SELECT jp.* FROM product jp LEFT JOIN base_community_dept_relation jdr ON jp.dept_id = jdr.dept_id AND jdr.is_vaild = 1 LEFT JOIN promote_active_product_relation japr ON jp.id = japr.product_id AND japr.is_vaild = 1 WHERE jp.is_list = 1 AND jp.marketable = 1 AND jp.default_display = 1 AND jp.product_category = ?1 GROUP BY jp.id ORDER BY jp.ranking DESC", nativeQuery = true)
    List<Product> getProductList(Long categoryId);

    @Query(value = "select * from product where productSn in (select productSn from product where id = ?1)", nativeQuery = true)
    List<Product> getProductListByProductSn(Long productId);
}
